/**
 * Created by on 2018/5/4.
 */
define(function () {

    var self,
        app = win.app,
        orderSubmitArg,
        jxschoose = [],
        searchData = {
            keyword: ''
        }
    ;

    var jxs = app.Module.extend({

        init: function () {
            self = this;
            orderSubmitArg = app.pageParameters['jxsinfo_page'];
            jxschoose.pushArray(orderSubmitArg.jxschoose, true).addMap({checked: '1'}, true);
            self._super({
                _sliderId: 'slider', // tabs
                _refreshAutoInit: true //自动加载刷新控件
            }, win);

        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat153/getJxsPage",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    keyword: searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data.data;
                        data.addMap({checked: false, GWBE003: 'N'});
                        for (var j = 0; j < jxschoose.length; j++) {
                            var item = jxschoose[j];
                            data.filterKV({GWAK001: item.GWAK001}).addMap({checked: '1', GWBE003: item.GWBE003}, true);
                        }

                        data.sort(function (v) {
                            return v.checked == '1' ? -1 : 1;
                        });

                        _super({
                            obj: goods,
                            data: data,
                            nodata: '无经销商信息...'
                        });
                    }
                }
            });
        },
        _search: function (data) {
            searchData.keyword = data.keyword.trim();
            self._refresh();
        },
        _lazy: function () {
            this._super();
            new Vue({
                el: app.getByid(doc, 'footer'),
                methods: {
                    addBtn: function () {
                        app.openPage({
                            src: "gwat153/gwat153-jxs-add.html",
                            argsKey: 'jxsadd_page',
                            args: {
                                cb: function (obj) {
                                    self._refresh();
                                }
                            }
                        });
                    },
                    sureBtn: function () {
                        orderSubmitArg.cb(jxschoose);
                        app.back(1);
                    }
                }
            });

            var sliderVue = new Vue({
                el: app.getByid(doc, 'sliderSegmentedControl'),
                data: {
                    jxschoose: jxschoose
                },
                methods: {}
            });

            new Vue({
                el: app.getByid(doc, 'scrollZ'),
                data: {
                    jxschoose: jxschoose
                },
                methods: {}
            });

            mui('#scrollZ').scroll({
                deceleration: 0.0005
            });
        },
        _ready: function () {

            Vue.component('jxsitem', {
                template: app.getByid(doc, 'customersitem-template'),
                props: {
                    model: Array
                },
                methods: {
                    select: function (v) {

                        if (v.checked == 1) {
                            jxschoose.push(v);
                        } else {
                            var arr = jxschoose.filterKV({GWAK001: v.GWAK001});
                            if (arr.length > 0) {
                                jxschoose.remove(arr[0]);
                            }
                        }
                    }
                }
            });

            Vue.component('jxsitem2', {
                template: app.getByid(doc, 'customersitem2-template'),
                props: {
                    model: Array
                },
                methods: {
                    select: function (v) {
                        self._getRefreshObj(0).data.filterKV({GWAK001: v.GWAK001}).addMap({checked: '0'}, true);
                        jxschoose.remove(v);
                    },
                    record: function (v) {

                    }
                }
            });

        }
    });

    return new jxs();

});